package klimuts.periodicals.admin;

import klimuts.periodicals.user.User;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * Intercept all administrator actions and redirect to login page if user is not administrator
 * @author Siarhei Klimuts
 *
 */
public class AdminInterceptor implements Interceptor {

	public void destroy() {	}

	public void init() { }

	public String intercept(ActionInvocation invocation) throws Exception {
		User user=(User)invocation.getInvocationContext().getSession().get("user");
		if((user!=null)&&(user.getRights()>0))
			return invocation.invoke();
		else
			return "login";
	}

}
